Controller 您所在的位置:网站首页 laravel repository service Controller

Controller

#Controller| 来源: 网络整理| 查看: 265

Ok, just to be clear... I have zero experience regarding a patterns using in app development. I created a few apps, but they were small. Now I want to do things right. I read a lot and try to do the best I can, in the terms of manageability of the code as the app will grow.

I am not saying that business logic should not be in models here, I am just saying that I would never even think about business logic being in models according to all tutorials that I found on Laravel. Everyone just define relationships in model and that is it. Everything else is in controllers.

But then again, maybe I understand wrong, what business logic is. I found this definition:

Business logic is the process, formula, algorithm, decision tree, methodology, query, or any other means used to perform a piece of work that is specific to an application.

But according to this definition, I would imagine that some validation can be in the model, or business rules that allow action/properties of the model

But what about another type of business logic? Say you have a user model and a pet model. Business rule is that user can have only two pets (yes it is non real :). This business rule is defined in model. But where should be the code, that decided what to do, and what to display to user, when he tries to register third pet? Should that also be in model? Is it still business logic? Or is it application logic?

That may be a wrong example, the model can simply send to view some flag that he is not eligible to register another pet, ok... My point is. The sequence of actions that follow some another actions. The whole algorithm (after register user, send the mail, create related models, set some basic attributes, decide what to display after registration is complete based on user input), that simply can not be in model...



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有